<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>peach.ga.base.GeneticAlgorithm</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="peach-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a href="http://code.google.com/p/peach">Peach - Computational Intelligence for Python</a></th>
          </tr></table></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        <a href="peach-module.html">Package&nbsp;peach</a> ::
        <a href="peach.ga-module.html">Package&nbsp;ga</a> ::
        <a href="peach.ga.base-module.html">Module&nbsp;base</a> ::
        Class&nbsp;GeneticAlgorithm
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
        <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
    onclick="toggle_private();">hide&nbsp;private</a>]</span></td></tr>
        <tr><td align="right"><span class="options"
            >[<a href="frames.html" target="_top">frames</a
            >]&nbsp;|&nbsp;<a href="peach.ga.base.GeneticAlgorithm-class.html"
            target="_top">no&nbsp;frames</a>]</span></td></tr>
      </table>
    </td>
  </tr>
</table>
<!-- ==================== CLASS DESCRIPTION ==================== -->
<h1 class="epydoc">Class GeneticAlgorithm</h1><p class="nomargin-top"><span class="codelink"><a href="peach.ga.base-pysrc.html#GeneticAlgorithm">source&nbsp;code</a></span></p>
<center>
<center>  <map id="uml_class_diagram_for_peach_ga_2" name="uml_class_diagram_for_peach_ga_2">
<area shape="rect" id="node49" href="javascript:void(0);" title="hash(x)" alt="" coords="609,31,885,49"/>
<area shape="rect" id="node49" href="javascript:void(0);" title="x+y" alt="" coords="609,52,885,71"/>
<area shape="rect" id="node49" href="javascript:void(0);" title="y in x" alt="" coords="609,71,885,89"/>
<area shape="rect" id="node49" href="javascript:void(0);" title="del x[y]" alt="" coords="609,89,885,108"/>
<area shape="rect" id="node49" href="javascript:void(0);" title="del x[i:j]" alt="" coords="609,108,885,127"/>
<area shape="rect" id="node49" href="javascript:void(0);" title="x==y" alt="" coords="609,127,885,145"/>
<area shape="rect" id="node49" href="javascript:void(0);" title="x&gt;=y" alt="" coords="609,145,885,164"/>
<area shape="rect" id="node49" href="javascript:void(0);" title="x.__getattribute__(&#39;name&#39;) &lt;==&gt; x.name" alt="" coords="609,164,885,183"/>
<area shape="rect" id="node49" href="javascript:void(0);" title="x[y]" alt="" coords="609,183,885,201"/>
<area shape="rect" id="node49" href="javascript:void(0);" title="x[i:j]" alt="" coords="609,201,885,220"/>
<area shape="rect" id="node49" href="javascript:void(0);" title="x&gt;y" alt="" coords="609,220,885,239"/>
<area shape="rect" id="node49" href="javascript:void(0);" title="x+=y" alt="" coords="609,239,885,257"/>
<area shape="rect" id="node49" href="javascript:void(0);" title="x*=y" alt="" coords="609,257,885,276"/>
<area shape="rect" id="node49" href="javascript:void(0);" title="iter(x)" alt="" coords="609,276,885,295"/>
<area shape="rect" id="node49" href="javascript:void(0);" title="stable sort IN PLACE; cmp(x, y) &#45;&gt; &#45;1, 0, 1" alt="" coords="609,313,885,332"/>
<area shape="rect" id="node1" href="javascript:void(0);" title="list() &#45;&gt; new empty list list(iterable) &#45;&gt; new list initialized from iterable&#39;s items" alt="" coords="597,6,896,338"/>
<area shape="rect" id="node48" href="peach.ga.base.GeneticAlgorithm-class.html#elitist" title="If True, then the population is elitist." alt="" coords="17,383,1477,401"/>
<area shape="rect" id="node48" href="peach.ga.base.GeneticAlgorithm-class.html#ranges" title="Holds the ranges for every variable. Although it is a writable property, care should be taken in changing parameters before ending the convergence." alt="" coords="17,401,1477,420"/>
<area shape="rect" id="node48" href="peach.ga.base.GeneticAlgorithm-class.html#chromosome_size" title="This property hold the chromosome size for the population. Not writable." alt="" coords="17,420,1477,439"/>
<area shape="rect" id="node48" href="peach.ga.base.GeneticAlgorithm-class.html#fx" title="Array containing the fitness value for every estimate in the population. Not writeable." alt="" coords="17,439,1477,457"/>
<area shape="rect" id="node48" href="peach.ga.base.GeneticAlgorithm-class.html#best" title="Single vector containing the position of the best point found by all the individuals. Not writeable." alt="" coords="17,457,1477,476"/>
<area shape="rect" id="node48" href="peach.ga.base.GeneticAlgorithm-class.html#fbest" title="Single scalar value containing the function value of the best point by all the individuals. Not writeable." alt="" coords="17,476,1477,495"/>
<area shape="rect" id="node48" href="peach.ga.base.GeneticAlgorithm-class.html#fitness" title="Vector containing the fitness value for every individual in the population. This is not the same as the objective function value. Not writeable." alt="" coords="17,495,1477,513"/>
<area shape="rect" id="node48" href="peach.ga.base.GeneticAlgorithm-class.html#__init__" title="Initializes the population and the algorithm." alt="" coords="17,516,1477,535"/>
<area shape="rect" id="node48" href="peach.ga.base.GeneticAlgorithm-class.html#sanity" title="Sanitizes the chromosomes in the population." alt="" coords="17,535,1477,553"/>
<area shape="rect" id="node48" href="peach.ga.base.GeneticAlgorithm-class.html#restart" title="Resets the optimizer, allowing the use of a new set of estimates. This can be used to avoid stagnation." alt="" coords="17,553,1477,572"/>
<area shape="rect" id="node48" href="peach.ga.base.GeneticAlgorithm-class.html#step" title="Computes a new generation of the population, a step of the adaptation." alt="" coords="17,572,1477,591"/>
<area shape="rect" id="node48" href="peach.ga.base.GeneticAlgorithm-class.html#__call__" title="Transparently executes the search until the minimum is found. The stop criteria are the maximum error or the maximum number of iterations, whichever is reached first. Note that this is a __call__ method, so the object is called as a function. This method returns a tuple (x, e), with the best estimate of the minimum and the error." alt="" coords="17,591,1477,609"/>
<area shape="rect" id="node2" href="peach.ga.base.GeneticAlgorithm-class.html" title="A standard Genetic Algorithm" alt="" coords="5,358,1488,615"/>
<area shape="rect" id="node3" href="peach.ga.base.GA-class.html" title="GA is an alias to GeneticAlgorithm" alt="" coords="720,635,776,674"/>
</map>
  <img src="uml_class_diagram_for_peach_ga_2.gif" alt='' usemap="#uml_class_diagram_for_peach_ga_2" ismap="ismap" class="graph-without-title" />
</center>
</center>
<hr />
<p>A standard Genetic Algorithm</p>
<p>This class implements the methods to generate, initialize and evolve a
population of chromosomes according to a given fitness function. A standard
GA implements, in this order:</p>
<blockquote>
<ul class="rst-simple">
<li>A selection method, to choose, from this generation, which individuals
will be present in the next generation;</li>
<li>A crossover method, to exchange information between selected individuals
to add diversity to the population;</li>
<li>A mutation method, to change information in a selected individual, also
to add diversity to the population;</li>
<li>The reinsertion of the fittest individual, if the population is elitist
(which is almost always the case).</li>
</ul>
</blockquote>
<p>A population is actually a list of chromosomes, and individuals can be
read and set as in a normal list. Use the <tt class="rst-docutils literal">[ ]</tt> operators to access
individual chromosomes but please be aware that modifying the information on
the list before the end of convergence can cause unpredictable results. The
population and the algorithm have also other properties, check below to see
more information on them.</p>

<!-- ==================== INSTANCE METHODS ==================== -->
<a name="section-InstanceMethods"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Instance Methods</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-InstanceMethods"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">new empty list</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="peach.ga.base.GeneticAlgorithm-class.html#__init__" class="summary-sig-name">__init__</a>(<span class="summary-sig-arg">self</span>,
        <span class="summary-sig-arg">f</span>,
        <span class="summary-sig-arg">x0</span>,
        <span class="summary-sig-arg">ranges</span>=<span class="summary-sig-default"><code class="variable-group">[</code><code class="variable-group">]</code></span>,
        <span class="summary-sig-arg">fmt</span>=<span class="summary-sig-default"><code class="variable-quote">'</code><code class="variable-string">f</code><code class="variable-quote">'</code></span>,
        <span class="summary-sig-arg">fitness</span>=<span class="summary-sig-default">&lt;class 'peach.ga.fitness.Fitness'&gt;</span>,
        <span class="summary-sig-arg">selection</span>=<span class="summary-sig-default">&lt;class 'peach.ga.selection.RouletteWheel'&gt;</span>,
        <span class="summary-sig-arg">crossover</span>=<span class="summary-sig-default">&lt;class 'peach.ga.crossover.TwoPoint'&gt;</span>,
        <span class="summary-sig-arg">mutation</span>=<span class="summary-sig-default">&lt;class 'peach.ga.mutation.BitToBit'&gt;</span>,
        <span class="summary-sig-arg">elitist</span>=<span class="summary-sig-default">True</span>)</span><br />
      Initializes the population and the algorithm.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="peach.ga.base-pysrc.html#GeneticAlgorithm.__init__">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr class="private">
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="__get_csize"></a><span class="summary-sig-name">__get_csize</span>(<span class="summary-sig-arg">self</span>)</span></td>
          <td align="right" valign="top">
            <span class="codelink"><a href="peach.ga.base-pysrc.html#GeneticAlgorithm.__get_csize">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr class="private">
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="__get_fx"></a><span class="summary-sig-name">__get_fx</span>(<span class="summary-sig-arg">self</span>)</span></td>
          <td align="right" valign="top">
            <span class="codelink"><a href="peach.ga.base-pysrc.html#GeneticAlgorithm.__get_fx">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr class="private">
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="__get_best"></a><span class="summary-sig-name">__get_best</span>(<span class="summary-sig-arg">self</span>)</span></td>
          <td align="right" valign="top">
            <span class="codelink"><a href="peach.ga.base-pysrc.html#GeneticAlgorithm.__get_best">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr class="private">
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="__get_fbest"></a><span class="summary-sig-name">__get_fbest</span>(<span class="summary-sig-arg">self</span>)</span></td>
          <td align="right" valign="top">
            <span class="codelink"><a href="peach.ga.base-pysrc.html#GeneticAlgorithm.__get_fbest">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr class="private">
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="__get_fit"></a><span class="summary-sig-name">__get_fit</span>(<span class="summary-sig-arg">self</span>)</span></td>
          <td align="right" valign="top">
            <span class="codelink"><a href="peach.ga.base-pysrc.html#GeneticAlgorithm.__get_fit">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="peach.ga.base.GeneticAlgorithm-class.html#sanity" class="summary-sig-name">sanity</a>(<span class="summary-sig-arg">self</span>)</span><br />
      Sanitizes the chromosomes in the population.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="peach.ga.base-pysrc.html#GeneticAlgorithm.sanity">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="peach.ga.base.GeneticAlgorithm-class.html#restart" class="summary-sig-name">restart</a>(<span class="summary-sig-arg">self</span>,
        <span class="summary-sig-arg">x0</span>)</span><br />
      Resets the optimizer, allowing the use of a new set of estimates. This
can be used to avoid stagnation.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="peach.ga.base-pysrc.html#GeneticAlgorithm.restart">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="peach.ga.base.GeneticAlgorithm-class.html#step" class="summary-sig-name">step</a>(<span class="summary-sig-arg">self</span>)</span><br />
      Computes a new generation of the population, a step of the adaptation.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="peach.ga.base-pysrc.html#GeneticAlgorithm.step">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="peach.ga.base.GeneticAlgorithm-class.html#__call__" class="summary-sig-name">__call__</a>(<span class="summary-sig-arg">self</span>)</span><br />
      Transparently executes the search until the minimum is found. The stop
criteria are the maximum error or the maximum number of iterations,
whichever is reached first. Note that this is a <tt class="rst-docutils literal">__call__</tt> method, so
the object is called as a function. This method returns a tuple
<tt class="rst-docutils literal">(x, e)</tt>, with the best estimate of the minimum and the error.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="peach.ga.base-pysrc.html#GeneticAlgorithm.__call__">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
  <tr>
    <td colspan="2" class="summary">
    <p class="indent-wrapped-lines"><b>Inherited from <code>list</code></b>:
      <code>__add__</code>,
      <code>__contains__</code>,
      <code>__delitem__</code>,
      <code>__delslice__</code>,
      <code>__eq__</code>,
      <code>__ge__</code>,
      <code>__getattribute__</code>,
      <code>__getitem__</code>,
      <code>__getslice__</code>,
      <code>__gt__</code>,
      <code>__iadd__</code>,
      <code>__imul__</code>,
      <code>__iter__</code>,
      <code>__le__</code>,
      <code>__len__</code>,
      <code>__lt__</code>,
      <code>__mul__</code>,
      <code>__ne__</code>,
      <code>__new__</code>,
      <code>__repr__</code>,
      <code>__reversed__</code>,
      <code>__rmul__</code>,
      <code>__setitem__</code>,
      <code>__setslice__</code>,
      <code>__sizeof__</code>,
      <code>append</code>,
      <code>count</code>,
      <code>extend</code>,
      <code>index</code>,
      <code>insert</code>,
      <code>pop</code>,
      <code>remove</code>,
      <code>reverse</code>,
      <code>sort</code>
      </p>
    <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
      <code>__delattr__</code>,
      <code>__format__</code>,
      <code>__reduce__</code>,
      <code>__reduce_ex__</code>,
      <code>__setattr__</code>,
      <code>__str__</code>,
      <code>__subclasshook__</code>
      </p>
    </td>
  </tr>
</table>
<!-- ==================== CLASS VARIABLES ==================== -->
<a name="section-ClassVariables"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Class Variables</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-ClassVariables"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
  <tr>
    <td colspan="2" class="summary">
    <p class="indent-wrapped-lines"><b>Inherited from <code>list</code></b>:
      <code>__hash__</code>
      </p>
    </td>
  </tr>
</table>
<!-- ==================== INSTANCE VARIABLES ==================== -->
<a name="section-InstanceVariables"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Instance Variables</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-InstanceVariables"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="elitist"></a><span class="summary-name">elitist</span><br />
      If <tt class="rst-docutils literal">True</tt>, then the population is elitist.
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="ranges"></a><span class="summary-name">ranges</span><br />
      Holds the ranges for every variable. Although it is a
writable property, care should be taken in changing parameters
before ending the convergence.
    </td>
  </tr>
</table>
<!-- ==================== PROPERTIES ==================== -->
<a name="section-Properties"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Properties</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-Properties"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="peach.ga.base.GeneticAlgorithm-class.html#chromosome_size" class="summary-name">chromosome_size</a><br />
      This property hold the chromosome size for the population. Not
writable.
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="peach.ga.base.GeneticAlgorithm-class.html#fx" class="summary-name">fx</a><br />
      Array containing the fitness value for every estimate in the
population. Not writeable.
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="peach.ga.base.GeneticAlgorithm-class.html#best" class="summary-name">best</a><br />
      Single vector containing the position of the best point found by all the
individuals. Not writeable.
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="peach.ga.base.GeneticAlgorithm-class.html#fbest" class="summary-name">fbest</a><br />
      Single scalar value containing the function value of the best point by
all the individuals. Not writeable.
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="peach.ga.base.GeneticAlgorithm-class.html#fitness" class="summary-name">fitness</a><br />
      Vector containing the fitness value for every individual in the
population. This is not the same as the objective function value. Not
writeable.
    </td>
  </tr>
  <tr>
    <td colspan="2" class="summary">
    <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
      <code>__class__</code>
      </p>
    </td>
  </tr>
</table>
<!-- ==================== METHOD DETAILS ==================== -->
<a name="section-MethodDetails"></a>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Method Details</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-MethodDetails"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
</table>
<a name="__init__"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">__init__</span>(<span class="sig-arg">self</span>,
        <span class="sig-arg">f</span>,
        <span class="sig-arg">x0</span>,
        <span class="sig-arg">ranges</span>=<span class="sig-default"><code class="variable-group">[</code><code class="variable-group">]</code></span>,
        <span class="sig-arg">fmt</span>=<span class="sig-default"><code class="variable-quote">'</code><code class="variable-string">f</code><code class="variable-quote">'</code></span>,
        <span class="sig-arg">fitness</span>=<span class="sig-default">&lt;class 'peach.ga.fitness.Fitness'&gt;</span>,
        <span class="sig-arg">selection</span>=<span class="sig-default">&lt;class 'peach.ga.selection.RouletteWheel'&gt;</span>,
        <span class="sig-arg">crossover</span>=<span class="sig-default">&lt;class 'peach.ga.crossover.TwoPoint'&gt;</span>,
        <span class="sig-arg">mutation</span>=<span class="sig-default">&lt;class 'peach.ga.mutation.BitToBit'&gt;</span>,
        <span class="sig-arg">elitist</span>=<span class="sig-default">True</span>)</span>
    <br /><em class="fname">(Constructor)</em>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="peach.ga.base-pysrc.html#GeneticAlgorithm.__init__">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <p>Initializes the population and the algorithm.</p>
<p>On the initialization of the population, a lot of parameters can be set.
Those will deeply affect the results. The parameters are:</p>
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><p><strong class="pname"><code>f</code></strong> - A multivariable function to be evaluated. The nature of the
parameters in the objective function will depend of the way you want
the genetic algorithm to process. It can be a standard function that
receives a one-dimensional array of values and computes the value of
the function. In this case, the values will be passed as a tuple,
instead of an array. This is so that integer, floats and other types
of values can be passed and processed. In this case, the values will
depend of the format string (see below)</p>
<p>If you don't supply a format, your objective function will receive a
<tt class="rst-docutils literal">Chromosome</tt> instance, and it is the responsability of the
function to decode the array of bits in any way. Notice that, while
it is more flexible, it is certainly more difficult to deal with.
Your function should process the bits and compute the return value
which, in any case, should be a scalar.</p>
<p>Please, note that genetic algorithms maximize functions, so project
your objective function accordingly. If you want to minimize a
function, return its negated value.</p></li>
        <li><strong class="pname"><code>x0</code></strong> - A population of first estimates. This is a list, array or tuple of
one-dimension arrays, each one corresponding to an estimate of the
position of the minimum. The population size of the algorithm will
be the same as the number of estimates in this list. Each component
of the vectors in this list are one of the variables in the function
to be optimized.</li>
        <li><p><strong class="pname"><code>ranges</code></strong> - Since messing with the bits can change substantially the values
obtained can diverge a lot from the maximum point. To avoid this,
you can specify a range for each of the variables. <tt class="rst-docutils literal">range</tt>
defaults to <tt class="rst-docutils literal">[ ]</tt>, this means that no range checkin will be done.
If given, then every variable will be checked. There are two ways to
specify the ranges.</p>
<p>It might be a tuple of two values, <tt class="rst-docutils literal">(x0, x1)</tt>, where <tt class="rst-docutils literal">x0</tt> is the
start of the interval, and <tt class="rst-docutils literal">x1</tt> its end. Obviously, <tt class="rst-docutils literal">x0</tt> should
be smaller than <tt class="rst-docutils literal">x1</tt>. If <tt class="rst-docutils literal">range</tt> is given in this way, then this
range will be used for every variable.</p>
<p>It can be specified as a list of tuples with the same format as
given above. In that case, the list must have one range for every
variable specified in the format and the ranges must appear in the
same order as there. That is, every variable must have a range
associated to it.</p></li>
        <li><p><strong class="pname"><code>fmt</code></strong> - A <tt class="rst-docutils literal">struct</tt>-format string. The <tt class="rst-docutils literal">struct</tt> module is a standard
Python module that packs and unpacks informations in bits. These
are used to inform the algorithm what types of data are to be used.
For example, if you are maximizing a function of three real
variables, the format should be something like <tt class="rst-docutils literal">&quot;fff&quot;</tt>. Any type
supported by the <tt class="rst-docutils literal">struct</tt> module can be used. The GA will decode
the bit array according to this format and send it as is to your
fitness function -- your function <em>must</em> know what to do with them.</p>
<p>Alternatively, the format can be an integer. In that case, the GA
will not try to decode the bit sequence. Instead, the bits are
passed without modification to the objective function, which must
deal with them. Notice that, if this is used this way, the
<tt class="rst-docutils literal">ranges</tt> property (see below) makes no sense, so it is set to
<tt class="rst-docutils literal">None</tt>. Also, no sanity checks will be performed.</p>
<p>It defaults to <code class="link">&quot;f&quot;</code>, that is, a single floating point variable.</p></li>
        <li><strong class="pname"><code>fitness</code></strong> - A fitness method to be applied over the objective function. This
parameter must be a <tt class="rst-docutils literal">Fitness</tt> instance or subclass. It will be
applied over the objective function to compute the fitness of every
individual in the population. Please, see the documentation on the
<tt class="rst-docutils literal">Fitness</tt> class.</li>
        <li><strong class="pname"><code>selection</code></strong> - This specifies the selection method. You can use one given in the
<tt class="rst-docutils literal">selection</tt> sub-module, or you can implement your own. In any
case, the <tt class="rst-docutils literal">selection</tt> parameter must be an instance of
<tt class="rst-docutils literal">Selection</tt> or of a subclass. Please, see the documentation on the
<tt class="rst-docutils literal">selection</tt> module for more information. Defaults to
<tt class="rst-docutils literal">RouletteWheel</tt>. If made <tt class="rst-docutils literal">None</tt>, then selection will not be
present in the GA.</li>
        <li><strong class="pname"><code>crossover</code></strong> - This specifies the crossover method. You can use one given in the
<tt class="rst-docutils literal">crossover</tt> sub-module, or you can implement your own. In any
case, the <tt class="rst-docutils literal">crossover</tt> parameter must be an instance of
<tt class="rst-docutils literal">Crossover</tt> or of a subclass. Please, see the documentation on the
<tt class="rst-docutils literal">crossover</tt> module for more information. Defaults to
<tt class="rst-docutils literal">TwoPoint</tt>. If made <tt class="rst-docutils literal">None</tt>, then crossover will not be
present in the GA.</li>
        <li><strong class="pname"><code>mutation</code></strong> - This specifies the mutation method. You can use one given in the
<tt class="rst-docutils literal">mutation</tt> sub-module, or you can implement your own. In any
case, the <tt class="rst-docutils literal">mutation</tt> parameter must be an instance of <tt class="rst-docutils literal">Mutation</tt>
or of a subclass. Please, see the documentation on the <tt class="rst-docutils literal">mutation</tt>
module for more information. Defaults to <tt class="rst-docutils literal">BitToBit</tt>.  If made
<tt class="rst-docutils literal">None</tt>, then mutation will not be present in the GA.</li>
        <li><strong class="pname"><code>elitist</code></strong> - Defines if the population is elitist or not. An elitist population
will never discard the fittest individual when a new generation is
computed. Defaults to <tt class="rst-docutils literal">True</tt>.</li>
    </ul></dd>
    <dt>Returns: new empty list</dt>
    <dt>Overrides:
        object.__init__
    </dt>
  </dl>
</td></tr></table>
</div>
<a name="sanity"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">sanity</span>(<span class="sig-arg">self</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="peach.ga.base-pysrc.html#GeneticAlgorithm.sanity">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <p>Sanitizes the chromosomes in the population.</p>
<p>Since not every individual generated by the crossover and mutation
operations might be a valid result, this method verifies if they are
inside the allowed ranges (or if it is a number at all). Each invalid
individual is discarded and a new one is generated.</p>
<p>This method has no parameters and returns no values.</p>
  <dl class="fields">
  </dl>
</td></tr></table>
</div>
<a name="restart"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">restart</span>(<span class="sig-arg">self</span>,
        <span class="sig-arg">x0</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="peach.ga.base-pysrc.html#GeneticAlgorithm.restart">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  Resets the optimizer, allowing the use of a new set of estimates. This
can be used to avoid stagnation.
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>x0</code></strong> - A new set of estimates. It doesn't need to have the same size of the
original population, but it must be a list of estimates in the same
format as in the object instantiation. Please, see the documentation
on the instantiation of the class.</li>
    </ul></dd>
  </dl>
</td></tr></table>
</div>
<a name="step"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">step</span>(<span class="sig-arg">self</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="peach.ga.base-pysrc.html#GeneticAlgorithm.step">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <p>Computes a new generation of the population, a step of the adaptation.</p>
<p>This method goes through all the steps of the GA, as described above. If
the selection, crossover and mutation operators are defined, they are
applied over the population. If the population is elitist, then the
fittest individual of the past generation is reinserted.</p>
<p>This method has no parameters and returns no values. The GA itself can
be consulted (using <tt class="rst-docutils literal">[ ]</tt>) to find the fittest individual which is the
result of the process.</p>
  <dl class="fields">
  </dl>
</td></tr></table>
</div>
<a name="__call__"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">__call__</span>(<span class="sig-arg">self</span>)</span>
    <br /><em class="fname">(Call operator)</em>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="peach.ga.base-pysrc.html#GeneticAlgorithm.__call__">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  Transparently executes the search until the minimum is found. The stop
criteria are the maximum error or the maximum number of iterations,
whichever is reached first. Note that this is a <tt class="rst-rst-docutils literal rst-docutils literal">__call__</tt> method, so
the object is called as a function. This method returns a tuple
<tt class="rst-rst-docutils literal rst-docutils literal">(x, e)</tt>, with the best estimate of the minimum and the error.
  <dl class="fields">
    <dt>Returns:</dt>
        <dd>This method returns a tuple <tt class="rst-docutils literal">(x, e)</tt>, where <tt class="rst-docutils literal">x</tt> is the best
estimate of the minimum, and <tt class="rst-docutils literal">e</tt> is the estimated error.</dd>
  </dl>
</td></tr></table>
</div>
<br />
<!-- ==================== PROPERTY DETAILS ==================== -->
<a name="section-PropertyDetails"></a>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Property Details</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-PropertyDetails"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
</table>
<a name="chromosome_size"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <h3 class="epydoc">chromosome_size</h3>
  This property hold the chromosome size for the population. Not
writable.
  <dl class="fields">
    <dt>Get Method:</dt>
    <dd class="value"><span class="summary-sig"><a href="peach.ga.base.GeneticAlgorithm-class.html#__get_csize" class="summary-sig-name" onclick="show_private();">__get_csize</a>(<span class="summary-sig-arg">self</span>)</span>
    </dd>
  </dl>
</td></tr></table>
</div>
<a name="fx"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <h3 class="epydoc">fx</h3>
  Array containing the fitness value for every estimate in the
population. Not writeable.
  <dl class="fields">
    <dt>Get Method:</dt>
    <dd class="value"><span class="summary-sig"><a href="peach.ga.base.GeneticAlgorithm-class.html#__get_fx" class="summary-sig-name" onclick="show_private();">__get_fx</a>(<span class="summary-sig-arg">self</span>)</span>
    </dd>
  </dl>
</td></tr></table>
</div>
<a name="best"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <h3 class="epydoc">best</h3>
  Single vector containing the position of the best point found by all the
individuals. Not writeable.
  <dl class="fields">
    <dt>Get Method:</dt>
    <dd class="value"><span class="summary-sig"><a href="peach.ga.base.GeneticAlgorithm-class.html#__get_best" class="summary-sig-name" onclick="show_private();">__get_best</a>(<span class="summary-sig-arg">self</span>)</span>
    </dd>
  </dl>
</td></tr></table>
</div>
<a name="fbest"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <h3 class="epydoc">fbest</h3>
  Single scalar value containing the function value of the best point by
all the individuals. Not writeable.
  <dl class="fields">
    <dt>Get Method:</dt>
    <dd class="value"><span class="summary-sig"><a href="peach.ga.base.GeneticAlgorithm-class.html#__get_fbest" class="summary-sig-name" onclick="show_private();">__get_fbest</a>(<span class="summary-sig-arg">self</span>)</span>
    </dd>
  </dl>
</td></tr></table>
</div>
<a name="fitness"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <h3 class="epydoc">fitness</h3>
  Vector containing the fitness value for every individual in the
population. This is not the same as the objective function value. Not
writeable.
  <dl class="fields">
    <dt>Get Method:</dt>
    <dd class="value"><span class="summary-sig"><a href="peach.ga.base.GeneticAlgorithm-class.html#__get_fit" class="summary-sig-name" onclick="show_private();">__get_fit</a>(<span class="summary-sig-arg">self</span>)</span>
    </dd>
  </dl>
</td></tr></table>
</div>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="peach-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a href="http://code.google.com/p/peach">Peach - Computational Intelligence for Python</a></th>
          </tr></table></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">
    Generated by Epydoc 3.0.1 on Sun Jul 31 16:59:36 2011
    </td>
    <td align="right" class="footer">
      <a target="mainFrame" href="http://epydoc.sourceforge.net"
        >http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie();
  // -->
</script>
</body>
</html>
